package com.example.myapplication.ui.Splash;

import android.content.Intent;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.base.ActivityManager;
import com.example.myapplication.base.BaseActivity;
import com.example.myapplication.ui.Splashview.GuideActivity;
import com.example.myapplication.ui.wight.CircleImageView;

import java.util.Random;

import butterknife.BindView;

public class SplashActivity extends BaseActivity {

    @BindView(R.id.iv_background)
    ImageView mIvBackground;

    @BindView(R.id.iv_splash_image)
    CircleImageView mIcSplashImage ;

    @Override
    protected int getLayout() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        return R.layout.activity_splash;
    }

    @Override
    protected void initView() {
        ActivityManager.addActivity(this);
        int[] images = {R.mipmap.splash_01,R.mipmap.splash_02,R.mipmap.splash_03,R.mipmap.splash_04};
        int position = new Random().nextInt(images.length - 1) % (images.length);
        Glide.with(this).load(images[position]).into(mIvBackground);
//        Picasso.with(this)
//                .load(images[position])
//                .into(mIvBackground);
        TranslateAnimation translateAnimation =new TranslateAnimation(
                Animation.RELATIVE_TO_SELF,0f,
                Animation.RELATIVE_TO_SELF,0f,
                Animation.RELATIVE_TO_SELF,2f,
                Animation.RELATIVE_TO_SELF,0f);
       // AlphaAnimation animation =new AlphaAnimation(0.1f,0.1f);
        translateAnimation.setDuration(2000);
        mIcSplashImage.setAnimation(translateAnimation);
        translateAnimation.setAnimationListener(new AnimactionImpl());
    }


    private  class  AnimactionImpl implements Animation.AnimationListener{

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            startActivity(new Intent(SplashActivity.this,GuideActivity.class));
            ActivityManager.finishActivity(SplashActivity.this);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    }

    @Override
    public void onBackPressed() {

    }
}
